<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>The source code</title>
  <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  <style type="text/css">
    .highlight { display: block; background-color: #ddd; }
  </style>
  <script type="text/javascript">
    function highlight() {
      document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
    }
  </script>
</head>
<body onload="prettyPrint(); highlight();">
  <pre class="prettyprint lang-js"><span id='global-property-'>/**
</span> * @ignore
 * base custom event mechanism for kissy
 * @author yiminghe@gmail.com
 */
KISSY.add('event/base/observable', function (S) {

<span id='KISSY-Event-Observable'>    /**
</span>     * base custom event for registering and un-registering observer for specified event.
     * @class KISSY.Event.Observable
     * @private
     * @param {Object} cfg custom event's attribute
     */
    function Observable(cfg) {
        var self = this;
        self.currentTarget = null;
        S.mix(self, cfg);
        self.reset();
<span id='KISSY-Event-Observable-cfg-type'>        /**
</span>         * current event type
         * @cfg {String} type
         */
    }

    Observable.prototype = {

        constructor: Observable,

<span id='KISSY-Event-Observable-method-hasObserver'>        /**
</span>         * whether current event has observers
         * @return {Boolean}
         */
        hasObserver: function () {
            return !!this.observers.length;
        },

<span id='KISSY-Event-Observable-method-reset'>        /**
</span>         * reset current event's status
         */
        reset: function () {
            var self = this;
            self.observers = [];
        },

<span id='KISSY-Event-Observable-method-removeObserver'>        /**
</span>         * remove one observer from current event's observers
         * @param {KISSY.Event.Observer} observer
         */
        removeObserver: function (observer) {
            var self = this,
                i,
                observers = self.observers,
                len = observers.length;
            for (i = 0; i &lt; len; i++) {
                if (observers[i] == observer) {
                    observers.splice(i, 1);
                    break;
                }
            }
            self.checkMemory();
        },

<span id='KISSY-Event-Observable-method-checkMemory'>        /**
</span>         * check memory after detach
         * @private
         */
        checkMemory: function () {

        },

<span id='KISSY-Event-Observable-method-findObserver'>        /**
</span>         * Search for a specified observer within current event's observers
         * @param {KISSY.Event.Observer} observer
         * @return {Number} observer's index in observers
         */
        findObserver: function (observer) {
            var observers = this.observers, i;

            for (i = observers.length - 1; i &gt;= 0; --i) {
                /*
                 If multiple identical EventListeners are registered on the same EventTarget
                 with the same parameters the duplicate instances are discarded.
                 They do not cause the EventListener to be called twice
                 and since they are discarded
                 they do not need to be removed with the removeEventListener method.
                 */
                if (observer.equals(observers[i])) {
                    return i;
                }
            }

            return -1;
        }
    };

    return Observable;

});</pre>
</body>
</html>
